import {describeCrontab} from "../describe";
import {preNormalize} from "../pre_normize";
import {expect} from "chai";

describe('describe parts', () => {
  context("分", () => {
    const monthParts = [
      {input: '*', expect: '每分钟'},
      {input: '1', expect: '01分'},
      {input: '*/3', expect: '每3分钟'},
      {input: '1-10', expect: '01到10分之间的每一分钟'},
      {input: '0-11/2', expect: '00到11分之间每隔2分钟'},
    ].slice(0, 5)

    for (const testCase of monthParts) {
      it(`${testCase.input} => ${testCase.expect}`, () => {
          const desc = describeCrontab(preNormalize(`${testCase.input} 2,3 1 1 *`))
          expect(desc.minutes)
            .to.equal(testCase.expect)
        }
      )
    }
  })

  context("时", () => {
    const monthParts = [
      {input: '*', expect: null},
      {input: '1', expect: '1点'},
      {input: '*/3', expect: '每3小时'},
      {input: '1-10', expect: '1点到10点'},
      {input: '0-11/2', expect: '0点到11点之间每隔2小时'},
    ].slice(0, 5)

    for (const testCase of monthParts) {
      it(`${testCase.input} => ${testCase.expect}`, () => {
          const desc = describeCrontab(preNormalize(`1,2 ${testCase.input}  1 1 *`))
          expect(desc.hours)
            .to.equal(testCase.expect)
        }
      )
    }
  })

  context("日", () => {
    const monthParts = [
      {input: '*', expect: null},
      {input: '1', expect: '一号'},
      {input: '*/3', expect: '每3天'},
      {input: '1-9', expect: '一到九号'},
      {input: '1-11/2', expect: '一到十一号中的每2天'},
    ].slice(0, 5)

    for (const testCase of monthParts) {
      it(`${testCase.input} => ${testCase.expect}`, () => {
          const desc = describeCrontab(preNormalize(`1 2 ${testCase.input} 1 *`))
          expect(desc.dates)
            .to.equal(testCase.expect)
        }
      )
    }
  })

  context("月", () => {
    const monthParts = [
      {input: '*', expect: null},
      {input: '1', expect: '一月'},
      {input: '*/3', expect: '每3个月'},
      {input: '1-9', expect: '一到九月'},
      {input: '1-11/2', expect: '一到十一月中的每2个月'},
    ].slice(0, 5)

    for (const testCase of monthParts) {
      it(`${testCase.input} => ${testCase.expect}`, () => {
          const desc = describeCrontab(preNormalize(`1 2 */3 ${testCase.input} *`))
          expect(desc.months)
            .to.equal(testCase.expect)
        }
      )
    }
  })

  context("周", () => {
    const monthParts = [
      {input: '*', expect: null},
      {input: '1', expect: '周一'},
      {input: '*/3', expect: '周日,周三,周六'},
      {input: '1-3', expect: '周一到周三'},
      {input: '1-5/2', expect: '周一到周五每隔2天'},
    ].slice(0, 5)

    for (const testCase of monthParts) {
      it(`${testCase.input} => ${testCase.expect}`, () => {
          const desc = describeCrontab(preNormalize(`1 1 * * ${testCase.input}`))
          expect(desc.weekdays)
            .to.equal(testCase.expect)
        }
      )
    }
  })

})
